package operation;

import book.Book;
import book.bookList;

import java.util.Scanner;

public class Deletoperation implements Listoperation{
    @Override
    public void work(bookList booklist) {
        System.out.println("删除图书...");
        Scanner sc=new Scanner(System.in);
        if(booklist.getUsesize()==0){
            System.out.println("书架上没有书，删除失败");
            return ;
        }
        System.out.println("请输入要删除的书名:");
        String name=sc.nextLine();
        int x= booklist.getInstance(name);
        for (int i = x; i < booklist.getUsesize()-1; i++) {
            booklist.swap(booklist.getBooks(i),booklist.getBooks(i+1));
        }
        booklist.setUsesize(booklist.getUsesize()-1);
        System.out.println("删除成功");
    }
}
